1 : <?php
2 : /*--------------------------------------------------------------------------+
3 : This file is part of eStudy.
4 : common/class.automation.inc.php
5 : - Modulgruppe: Framework
6 : - Beschreibung: Klasse um abhandeln automatisierter Funktionen des Frameworks
7 : - Version: 0.6, 26/03/04
8 : - Autor(en): Christian Gerhardt <case42@gmx.net
9 : +---------------------------------------------------------------------------+
10 : This program is free software; you can redistribute it and/or
11 : modify it under the terms of the GNU General Public License
12 : as published by the Free Software Foundation; either version 2
13 : of the License, or any later version.
14 : +---------------------------------------------------------------------------+
15 : This program is distributed in the hope that it will be useful,
16 : but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : GNU General Public License for more details.
19 : You should have received a copy of the GNU General Public License
20 : along with this program; if not, write to the Free Software
21 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 : +--------------------------------------------------------------------------*/
23 : /**
24 : * In dieser Datei wird die Klasse Automation implementiert.
25 : * @version 0.6, 26/03/04
26 : * @author Christian Gerhardt <case42@gmx.net>
27 : * @package eStudy.Framework
28 : * @subpackage automation
29 : */
30 : // PHP-Timelimit auf 0 setzen, wenn möglich
31 1 : if (!ini_get('safe_mode'))
32 1 : set_time_limit(0);
33 : /**Für die Objektliste*/
34 1 : require_once ('class.container.inc.php');
35 : /**Die Basisklasse der Modul-Automation*/
36 1 : require_once ('class.modulautomation.inc.php');
37 : /**
38 : * Regelt und wickelt verschiedene Möglichkeiten der Automatisierung ab.
39 : * Möglich sind: tägliche und wöchendliche anstehende Arbeiten, sowie
40 : * Funktionen die automatisch beim Löschen eines Users, Dozenten, Hilfsadmins oder
41 : * einer Veranstaltung aufgerufen werden können.<br />
42 : * Um dies gewährleisten zu können, werden zunächst Objekte der
43 : * Klasse {@link ModulAutomation <strong>ModulAutomation</strong>} in einer Liste gesammelt, von der aus
44 : * dann die gewünschten Methoden aufgerufen werden können.<br />
45 : * Damit dies funktionieren kann muß von Seiten der Modulentwicklung auf einige Dinge
46 : * geachtet werden, wenn sie diese automatisierten Funktionen nutzen wollen.<br />
47 : * Zunächst muß eine Subklasse der Klasse {@link ModulAutomation <strong>ModulAutomation</strong>}
48 : * erzeugt werden, und die entsprechenden Methoden mit ihrer gewünschten Funktionalität
49 : * überschrieben werden. Dies sollte besonders in Hinsicht der evtl. zu leistenden
50 : * Aufräumarbeit getan werden, die anfällt, wenn z.b. ein User oder Dozent aus dem Portal
51 : * gelöscht wird.<br />
52 : * Danach ist es noch notwendig dem Portal die Möglichkeit zu geben die Methode auzuführen.
53 : * Dies geschieht folgendermaßen:<br />
54 : * Es muß eine Datei <em><strong>auto.inc.php</strong></em> erzegt werden und im Rootverzeichnis des Moduls
55 : * abgelegt werden. Bei einer Modulgruppe mit dem Namen <strong>Test</strong>, wäre das in der Regel
56 : * das Verzeichnis: <em>/website/test</em><br />
57 : * Wenn nun eine Klasse <em>TestModulAutomation</em> als Subklasse von {@link ModulAutomation <strong>ModulAutomation</strong>}
58 : * erzeugt wurde, muß die Datei <em><strong>auto.inc.php</strong></em> folgendermaßen aussehen:<br />
59 : * <br />
60 : * <code>
61 : * require(PATH_TO_ROOT."classes/class.testmodulautomation.inc.php");
62 : * $result = $container.add(new TestModulAutomation());
63 : * </code>
64 : * <br />
65 : * Die Variable $container ist die Liste in die das Objekt eingetragen wird und $result
66 : * speichert das Ergebnis dieser Funktion, für den Fall das ein Fehler auftritt und eine
67 : * Fehlerausgabe gemacht werden muß.<br />
68 : * Sollte zu einer Modulgruppe weder eine automatische Funktionalität noch eine Aufräumarbeit
69 : * anfallen, kann auf eine <em><strong>auto.inc.php</strong></em> Datei verzichtet werden.<br />
70 : *
71 : * @author Christian Gerhardt <case42@gmx.net>
72 : * @version 0.6, 26/03/04
73 : * @package eStudy.Framework
74 : * @subpackage automation
75 : */
76 1 : class Automation {
77 : /**
78 : * Ein Array mit FehlerStrings
79 : * @access protected
80 : * @var array
81 : */
82 : var $errorString = array();
83 : /**
84 : * Der Objektliste für ModulAutomation-Objekte
85 : * @access protected
86 : * @var Container
87 : */
88 : var $container = null;
89 : /**
90 : * Name und Pfad zum Logfile
91 : * @access protected
92 : * @var string
93 : */
94 : var $logFile;
95 : /**
96 : * FilePointer auf das geöffnete Logfile
97 : * @access protected
98 : * @var integer
99 : */
100 : var $logFilePointer = 0;
101 : /**
102 : * Ob Meldungen an den Browser übergeben werden sollen.
103 : * @access protected
104 : * @var bool
105 : */
106 : var $verbose = false;
107 : /**
108 : * Konstruktor zum setzen der Defaultwerte und einlesen der Objekte.
109 : * Der Konstruktor führt bereits die Methode {@link Automation::fetchObjects()} aus.<br />
110 : * Wird als <strong>$logFile</strong> ein leerer String übergeben, wird eine standart Logdatei
111 : * im Verzeichnis <strong>/logs</strong> mit dem Namen: <br /><strong>log-<em>aktuelles Datum</em>.log</strong>
112 : * angelegt.<br />
113 : * Wird <strong>NULL</strong> übergenben, werden keine Daten in die Logdatei geschrieben und diese
114 : * Funktionalität deaktiviert.
115 : *
116 : * @access public
117 : * @param string $logFile - der Name des Logfiles
118 : * @param bool $verbose - ob zusätzliche Meldungen ausgegeben werden sollen
119 : */
120 : function Automation($logFile = null, $verbose = false) {
121 0 : if (is_string($logFile) and $logFile != "") {
122 0 : $this->logFile = $logFile;
123 0 : } else {
124 : //default wert für logfile
125 0 : $this->logFile = PATH_TO_ROOT."logs/log-".date("Y-m-d") .".log";
126 : }
127 0 : if (!is_null($logFile)) $this->openLogFile();
128 0 : if (is_bool($verbose)) {
129 0 : $this->verbose = $verbose;
130 0 : } else {
131 : //defaultwert
132 0 : $this->verbose = false;
133 : }
134 : //objekte holen
135 0 : $this->fetchObjects();
136 0 : }
137 : /**
138 : * Sucht alle Verzeichnisse des Portals nach <strong>auto.inc.php</strong> Dateien durch und bindet diese ein.
139 : * Zunächst werden das in <strong>PATH_TO_ROOT</strong> angegebene Verzeichnis nach Unterverzeichnissen
140 : * durchsucht. Diese wären dann die ROOT-Verzeichnisse der einzelnen Module/Modulgruppen,
141 : * die nach den <strong>auto.inc.php</strong> Dateien durchsucht werden.<br />
142 : * <strong>VORSICHT!</strong><br />
143 : * Es wird nicht noch eine Stufe tiefer nach den Dateien gesucht, was bedeutet,
144 : * das alle <strong>auto.inc.php</strong> Dateien in den ROOT-Verzeichnissen der Module liegen müssen.
145 : * @access protected
146 : * @return void
147 : */
148 : function fetchObjects() {
149 : //neuen container für Modulautomation-Objekte erzeugen
150 0 : $container = new Container("modulautomation", "modulIsInstalled");
151 : //hierhin code zum einbinden der dateien und füllen des containers
152 0 : $this->writeToLogfile("Beginne mit Einbindungsvorgang...", "");
153 : //alle unterverzeichnisse des portal roots einlesen
154 0 : $d = dir(PATH_TO_ROOT);
155 0 : $verzeichnisse = array();
156 0 : while ($entry = $d->read()) {
157 : // die Verzeichnisse . und .. rausfiltern
158 0 : if ($entry != "." && $entry != ".." && $entry != "logs" && $entry != "styles" && $entry != "images") {
159 0 : if (is_dir($d->path.$entry)) {
160 0 : $verzeichnisse[] = $d->path.$entry;
161 0 : }
162 0 : }
163 0 : }
164 0 : $d->close();
165 0 : $this->writeToLogfile("Suche auto.inc.php Dateien...", "");
166 0 : $dateien = array();
167 0 : if (count($verzeichnisse) > 0) {
168 0 : foreach($verzeichnisse as $verzeichnis) {
169 0 : $datei = $verzeichnis."/auto.inc.php";
170 0 : if (file_exists($datei)) {
171 0 : $dateien[] = $datei;
172 0 : }
173 0 : }
174 0 : }
175 0 : if (count($dateien) > 0) {
176 0 : $this->writeToLogfile("Binde auto.inc.php Dateien ein...", "");
177 0 : foreach($dateien as $datei) {
178 0 : $result = true;
179 0 : include ($datei);
180 0 : if ($result === false) {
181 0 : $this->error($container->getErrorString());
182 0 : $this->writeToLogfile("Fehler beim Einlesen der Dateien: ".$container->getErrorString(), "");
183 0 : }
184 0 : }
185 0 : } else {
186 0 : $this->writeToLogfile("Keine auto.inc.php Dateien gefunden!", "");
187 : }
188 0 : $this->writeToLogfile("Einbindungsvorgang abgeschlossen - ".$container->count() ." Objekt(e) eingebunden.", "");
189 0 : $this->container = $container;
190 0 : }
191 : /**
192 : * Ruft die Methoden auf, die automatisierte Funktionen ausführen, wenn ein
193 : * User gelöscht wird.
194 : *
195 : * @access public
196 : * @param integer $userID - die ID des Studenten
197 : * @return bool - Erfolgwert
198 : */
199 : function deleteUser($userID) {
200 0 : if (!is_numeric($userID)) {
201 0 : $this->error("Keine gültige userID übergeben!");
202 0 : return false;
203 : } else {
204 0 : if ($this->container->count() > 0) {
205 0 : $this->openLogFile();
206 0 : $this->writeToLogFile("LÖSCHE USER $userID: ".date("d.m.Y H:i:s"), "");
207 0 : $count = $this->container->count();
208 0 : for ($i = 0 ; $i < $count ; $i++) {
209 0 : $object = $this->container->get($i);
210 0 : if ($object != null) {
211 0 : $object->setVerbose($this->verbose);
212 0 : $object->setFilePointer($this->logFilePointer);
213 0 : $this->writeToLogfile("BEARBEITE OBJEKT NR. ".($i+1) .": ".$object->getInfo(), "");
214 0 : if (!$object->deleteUser($userID)) {
215 0 : $this->writeToLogFile($object->echoErrorString("\r\n"), "");
216 0 : }
217 0 : } else {
218 0 : $this->writeToLogFile("BEARBEITE OBJEKT NR. ".($i+1), "");
219 0 : $this->error("Container: ".$this->container->errorString);
220 0 : $this->writeToLogFile("Container: ".$this->container->errorString, "");
221 : }
222 0 : }
223 0 : $this->writeToLogFile("FERTIG", "");
224 0 : $this->closeLogFile();
225 0 : }
226 0 : return true;
227 : }
228 : }
229 : /**
230 : * Ruft die Methoden auf, die täglich automatisierte Funktionen ausführen.
231 : *
232 : * @access public
233 : * @return void
234 : */
235 : function doDailyWork() {
236 0 : if ($this->container->count() > 0) {
237 0 : $this->openLogFile();
238 0 : $this->writeToLogFile("BEGINNE MIT TÄGLICHER ARBEIT: ".date("d.m.Y H:i:s"), "");
239 0 : $count = $this->container->count();
240 0 : for ($i = 0 ; $i < $count ; $i++) {
241 0 : $object = $this->container->get($i);
242 0 : if ($object != null) {
243 0 : $this->writeToLogfile("BEARBEITE OBJEKT NR. ".($i+1) .": ".$object->getInfo(), "");
244 0 : $object->setVerbose($this->verbose);
245 0 : $object->setFilePointer($this->logFilePointer);
246 0 : if (!$object->dailyWork()) {
247 0 : $this->writeToLogFile($object->echoErrorString("\r\n"), "");
248 0 : }
249 0 : } else {
250 0 : $this->writeToLogFile("BEARBEITE OBJEKT NR. ".($i+1), "");
251 0 : $this->error("Container: ".$this->container->errorString);
252 0 : $this->writeToLogFile("Container: ".$this->container->errorString, "");
253 : }
254 0 : }
255 0 : $this->writeToLogFile("BEENDE TÄGLICHE ARBEIT", "");
256 : /*
257 : * Löschen von temporären Passwörtern nach Systemautomation
258 : * verschoben. Automatisierte Arbeiten, haben an dieser Stelle
259 : * nix verloren!
260 : */
261 0 : } else {
262 0 : $this->writeToLogFile("Es wurden keine Auto-Objekte gefunden!", "");
263 : }
264 0 : return true;
265 : }
266 : /**
267 : * Ruft die Methoden auf, die wöchendliche automatisierte Funktionen ausführen.
268 : *
269 : * @access public
270 : * @return void
271 : */
272 : function doWeeklyWork() {
273 0 : if ($this->container->count() > 0) {
274 0 : $this->openLogFile();
275 0 : $this->writeToLogFile("BEGINNE MIT WÖCHENTLICHER ARBEIT: ".date("d.m.Y H:i:s"), "");
276 0 : $count = $this->container->count();
277 0 : for ($i = 0 ; $i < $count ; $i++) {
278 0 : $object = $this->container->get($i);
279 0 : if ($object != null) {
280 0 : $this->writeToLogfile("BEARBEITE OBJEKT NR. ".($i+1) .": ".$object->getInfo(), "");
281 0 : $object->setVerbose($this->verbose);
282 0 : $object->setFilePointer($this->logFilePointer);
283 0 : if (!$object->weeklyWork()) {
284 0 : $this->writeToLogFile($object->echoErrorString("\r\n"), "");
285 0 : }
286 0 : } else {
287 0 : $this->writeToLogFile("BEARBEITE OBJEKT NR. ".($i+1), "");
288 0 : $this->error("Nullpointer zurückgegeben!");
289 0 : $this->writeToLogFile("NULLPOINTER ZURÜCKGEGEBEN", "");
290 : }
291 0 : }
292 0 : $this->writeToLogFile("BEENDE WÖCHENTLICHE ARBEIT", "");
293 0 : $this->closeLogFile();
294 0 : }
295 0 : }
296 :
297 : /**
298 : * Muß aufgerufen werden, wenn ein User neu zu einem Kurs hinzu kommt.
299 : *
300 : * @access public
301 : * @param integer $userID - Die ID des neuen Kursteilnehmers
302 : * @param integer $courseID - die ID der Veranstaltung
303 : * @return bool - Erfolgwert
304 : */
305 : function addUserToCourse($userID, $courseID) {
306 0 : if (is_numeric($courseID) and is_numeric($userID)) {
307 0 : $count = $this->container->count();
308 0 : if ($count > 0) {
309 0 : $this->openLogFile();
310 0 : $this->writeToLogFile("NEUER KURSTEILNEMER ($userID) IN KURS $courseID: ".date("d.m.Y H:i:s"), "");
311 0 : for ($i = 0 ; $i < $count ; $i++) {
312 0 : $object = $this->container->get($i);
313 0 : if ($object != null) {
314 0 : $this->writeToLogfile("BEARBEITE OBJEKT NR. ".($i+1) .": ".$object->getInfo(), "");
315 0 : $object->setVerbose($this->verbose);
316 0 : $object->setFilePointer($this->logFilePointer);
317 0 : if (!$object->addUserToCourse($userID, $courseID)) {
318 0 : $this->writeToLogFile($object->echoErrorString("\r\n"), "");
319 0 : }
320 0 : } else {
321 0 : $this->writeToLogFile("BEARBEITE OBJEKT NR. ".($i+1), "");
322 0 : $this->error("Container: ".$this->container->errorString);
323 0 : $this->writeToLogFile("Container: ".$this->container->errorString, "");
324 : }
325 0 : }
326 0 : $this->writeToLogFile("FERTIG", "");
327 0 : $this->closeLogFile();
328 0 : }
329 0 : return true;
330 : } else {
331 0 : $this->error("Keine gültige courseID oder userID übergeben");
332 0 : return false;
333 : }
334 : }
335 :
336 : /**
337 : * Muß aufgerufen werden, wenn ein User neu zu einem eCommunity hinzu kommt.
338 : *
339 : * @access public
340 : * @param integer $userID - Die ID des neuen Kursteilnehmers
341 : * @param integer $courseID - die ID der Veranstaltung
342 : * @return bool - Erfolgwert
343 : */
344 : function addUserToEcommunity($userID, $courseID) {
345 0 : if (is_numeric($courseID) and is_numeric($userID)) {
346 0 : $count = $this->container->count();
347 0 : if ($count > 0) {
348 0 : $this->openLogFile();
349 0 : $this->writeToLogFile("NEUER ECOMMUNITYTEILNEMER ($userID) IN ECOMMUNITY $courseID: ".date("d.m.Y H:i:s"), "");
350 0 : for ($i = 0 ; $i < $count ; $i++) {
351 0 : $object = $this->container->get($i);
352 0 : if ($object != null) {
353 0 : $this->writeToLogfile("BEARBEITE OBJEKT NR. ".($i+1) .": ".$object->getInfo(), "");
354 0 : $object->setVerbose($this->verbose);
355 0 : $object->setFilePointer($this->logFilePointer);
356 0 : if (!$object->addUserToCourse($userID, $courseID)) {
357 0 : $this->writeToLogFile($object->echoErrorString("\r\n"), "");
358 0 : }
359 0 : if (!$object->addUserToEcommunity($userID, $courseID)) {
360 0 : $this->writeToLogFile($object->echoErrorString("\r\n"), "");
361 0 : }
362 0 : } else {
363 0 : $this->writeToLogFile("BEARBEITE OBJEKT NR. ".($i+1), "");
364 0 : $this->error("Container: ".$this->container->errorString);
365 0 : $this->writeToLogFile("Container: ".$this->container->errorString, "");
366 : }
367 0 : }
368 0 : $this->writeToLogFile("FERTIG", "");
369 0 : $this->closeLogFile();
370 0 : }
371 0 : return true;
372 : } else {
373 0 : $this->error("Keine gültige courseID oder userID übergeben");
374 0 : return false;
375 : }
376 : }
377 :
378 :
379 :
380 :
381 :
382 : /**
383 : * Muß aufgerufen werden, wenn ein User einen Kurs verläßt.
384 : *
385 : * @access public
386 : * @param integer $userID - Die ID des Kursteilnehmers
387 : * @param integer $courseID - die ID der Veranstaltung
388 : * @return bool - Erfolgwert
389 : */
390 : function deleteUserFromCourse($userID, $courseID) {
391 0 : if (is_numeric($courseID) and is_numeric($userID)) {
392 0 : $count = $this->container->count();
393 0 : if ($count > 0) {
394 0 : $this->openLogFile();
395 0 : $this->writeToLogFile("ENTFERNE KURSTEILNEMER ($userID) AUS KURS ($courseID): ".date("d.m.Y H:i:s"), "");
396 0 : for ($i = 0 ; $i < $count ; $i++) {
397 0 : $object = $this->container->get($i);
398 0 : if ($object != null) {
399 0 : $this->writeToLogfile("BEARBEITE OBJEKT NR. ".($i+1) .": ".$object->getInfo(), "");
400 0 : $object->setVerbose($this->verbose);
401 0 : $object->setFilePointer($this->logFilePointer);
402 0 : if (!$object->deleteUserFromCourse($userID, $courseID)) {
403 0 : $this->writeToLogFile($object->echoErrorString("\r\n"), "");
404 0 : }
405 0 : } else {
406 0 : $this->writeToLogFile("BEARBEITE OBJEKT NR. ".($i+1), "");
407 0 : $this->error("Container: ".$this->container->errorString);
408 0 : $this->writeToLogFile("Container: ".$this->container->errorString, "");
409 : }
410 0 : }
411 0 : $this->writeToLogFile("FERTIG", "");
412 0 : $this->closeLogFile();
413 0 : }
414 0 : return true;
415 : } else {
416 0 : $this->error("Keine gültige courseID oder userID übergeben");
417 0 : return false;
418 : }
419 : }
420 : /**
421 : * Muß aufgerufen werden, wenn ein Assistent in einem Kurs ernannt wird
422 : *
423 : * @access public
424 : * @param integer $userID - Die ID des neuen Assistenten
425 : * @param integer $courseID - die ID der Veranstaltung
426 : * @return bool - Erfolgwert
427 : */
428 : function addAssistentToCourse($userID, $courseID) {
429 0 : if (is_numeric($courseID) and is_numeric($userID)) {
430 0 : $count = $this->container->count();
431 0 : if ($count > 0) {
432 0 : $this->openLogFile();
433 0 : $this->writeToLogFile("NEUER TUTOR ($userID) IN KURS $courseID: ".date("d.m.Y H:i:s"), "");
434 0 : for ($i = 0 ; $i < $count ; $i++) {
435 0 : $object = $this->container->get($i);
436 0 : if ($object != null) {
437 0 : $this->writeToLogfile("BEARBEITE OBJEKT NR. ".($i+1) .": ".$object->getInfo(), "");
438 0 : $object->setVerbose($this->verbose);
439 0 : $object->setFilePointer($this->logFilePointer);
440 0 : if (!$object->addAssistentToCourse($userID, $courseID)) {
441 0 : $this->writeToLogFile($object->echoErrorString("\r\n"), "");
442 0 : }
443 0 : } else {
444 0 : $this->writeToLogFile("BEARBEITE OBJEKT NR. ".($i+1), "");
445 0 : $this->error("Container: ".$this->container->errorString);
446 0 : $this->writeToLogFile("Container: ".$this->container->errorString, "");
447 : }
448 0 : }
449 0 : $this->writeToLogFile("FERTIG", "");
450 0 : $this->closeLogFile();
451 0 : }
452 0 : return true;
453 : } else {
454 0 : $this->error("Keine gültige courseID oder userID übergeben");
455 0 : return false;
456 : }
457 : }
458 : /**
459 : * Muß aufgerufen werden, wenn ein Assistent seinen Status verliert.
460 : *
461 : * @access public
462 : * @param integer $userID - Die ID des neuen Assistenten
463 : * @param integer $courseID - die ID der Veranstaltung
464 : * @return bool - Erfolgwert
465 : */
466 : function deleteAssistentFromCourse($userID, $courseID) {
467 0 : if (is_numeric($courseID) and is_numeric($userID)) {
468 0 : $count = $this->container->count();
469 0 : if ($count > 0) {
470 0 : $this->openLogFile();
471 0 : $this->writeToLogFile("ENTFERNE TUTOR ($userID) AUS KURS $courseID: ".date("d.m.Y H:i:s"), "");
472 0 : for ($i = 0 ; $i < $count ; $i++) {
473 0 : $object = $this->container->get($i);
474 0 : if ($object != null) {
475 0 : $this->writeToLogfile("BEARBEITE OBJEKT NR. ".($i+1) .": ".$object->getInfo(), "");
476 0 : $object->setVerbose($this->verbose);
477 0 : $object->setFilePointer($this->logFilePointer);
478 0 : if (!$object->deleteAssistentFromCourse($userID, $courseID)) {
479 0 : $this->writeToLogFile($object->echoErrorString("\r\n"), "");
480 0 : }
481 0 : } else {
482 0 : $this->writeToLogFile("BEARBEITE OBJEKT NR. ".($i+1), "");
483 0 : $this->error("Container: ".$this->container->errorString);
484 0 : $this->writeToLogFile("Container: ".$this->container->errorString, "");
485 : }
486 0 : }
487 0 : $this->writeToLogFile("FERTIG", "");
488 0 : $this->closeLogFile();
489 0 : }
490 0 : return true;
491 : } else {
492 0 : $this->error("Keine gültige courseID oder userID übergeben");
493 0 : return false;
494 : }
495 : }
496 : /**
497 : * Ruft die Methoden auf, die automatisierte Funktionen ausführen, wenn eine Veranstaltung geändert wird.
498 : *
499 : * @access public
500 : * @param integer $courseID - die ID der Veranstaltung
501 : * @return bool - Erfolgwert
502 : */
503 : function updateCourse($courseID) {
504 0 : if (!is_integer($courseID)) {
505 0 : $this->error("Keine gültige courseID übergeben");
506 0 : return false;
507 : } else {
508 0 : $count = $this->container->count();
509 0 : if ($count > 0) {
510 0 : $this->openLogFile();
511 0 : $this->writeToLogFile("AKTUALISIERE KURS $courseID: ".date("d.m.Y H:i:s"), "");
512 0 : for ($i = 0 ; $i < $count ; $i++) {
513 0 : $object = $this->container->get($i);
514 0 : if ($object != null) {
515 0 : $this->writeToLogfile("BEARBEITE OBJEKT NR. ".($i+1) .": ".$object->getInfo(), "");
516 0 : $object->setVerbose($this->verbose);
517 0 : $object->setFilePointer($this->logFilePointer);
518 0 : if (!$object->updateCourse($courseID)) {
519 0 : $this->writeToLogFile($object->echoErrorString("\r\n"), "");
520 0 : }
521 0 : } else {
522 0 : $this->writeToLogFile("BEARBEITE OBJEKT NR. ".($i+1), "");
523 0 : $this->error("Container: ".$this->container->errorString);
524 0 : $this->writeToLogFile("Container: ".$this->container->errorString, "");
525 : }
526 0 : }
527 0 : $this->writeToLogFile("FERTIG", "");
528 0 : $this->closeLogFile();
529 0 : }
530 0 : return true;
531 : }
532 : }
533 : /**
534 : * Ruft die Methoden auf, die automatisierte Funktionen ausführen, wenn eine Veranstaltung gelöscht wird.
535 : *
536 : * @access public
537 : * @param integer $courseID - die ID der Veranstaltung
538 : * @return bool - Erfolgwert
539 : */
540 : function deleteCourse($courseID) {
541 0 : if (!is_integer($courseID)) {
542 0 : $this->error("Keine gültige courseID übergeben");
543 0 : return false;
544 : } else {
545 0 : $count = $this->container->count();
546 0 : if ($count > 0) {
547 0 : $this->openLogFile();
548 0 : $this->writeToLogFile("LÖSCHE KURS $courseID: ".date("d.m.Y H:i:s"), "");
549 0 : for ($i = 0 ; $i < $count ; $i++) {
550 0 : $object = $this->container->get($i);
551 0 : if ($object != null) {
552 0 : $this->writeToLogfile("BEARBEITE OBJEKT NR. ".($i+1) .": ".$object->getInfo(), "");
553 0 : $object->setVerbose($this->verbose);
554 0 : $object->setFilePointer($this->logFilePointer);
555 0 : if (!$object->deleteCourse($courseID)) {
556 0 : $this->writeToLogFile($object->echoErrorString("\r\n"), "");
557 0 : }
558 0 : } else {
559 0 : $this->writeToLogFile("BEARBEITE OBJEKT NR. ".($i+1), "");
560 0 : $this->error("Container: ".$this->container->errorString);
561 0 : $this->writeToLogFile("Container: ".$this->container->errorString, "");
562 : }
563 0 : }
564 0 : $this->writeToLogFile("FERTIG", "");
565 0 : $this->closeLogFile();
566 0 : }
567 0 : return true;
568 : }
569 : }
570 : /**
571 : * Ruft die Methoden auf, die automatisierte Funktionen ausführen, wenn eine Veranstaltung archiviert wird.
572 : *
573 : * @access public
574 : * @param integer $courseID - die ID der Veranstaltung
575 : * @return bool - Erfolgwert
576 : */
577 : function archiveCourse($courseID) {
578 0 : if (!is_numeric($courseID)) {
579 0 : $this->error("Keine gültige courseID übergeben");
580 0 : return false;
581 : } else {
582 0 : $count = $this->container->count();
583 0 : if ($count > 0) {
584 0 : $this->openLogFile();
585 0 : $this->writeToLogFile("ARCHIVIERE KURS $courseID: ".date("d.m.Y H:i:s"), "");
586 0 : for ($i = 0 ; $i < $count ; $i++) {
587 0 : $object = $this->container->get($i);
588 0 : if ($object != null) {
589 0 : $this->writeToLogfile("BEARBEITE OBJEKT NR. ".($i+1) .": ".$object->getInfo(), "");
590 0 : $object->setVerbose($this->verbose);
591 0 : $object->setFilePointer($this->logFilePointer);
592 0 : if (!$object->archiveCourse($courseID)) {
593 0 : $this->writeToLogFile($object->echoErrorString("\r\n"), "");
594 0 : }
595 0 : } else {
596 0 : $this->writeToLogFile("BEARBEITE OBJEKT NR. ".($i+1), "");
597 0 : $this->error("Container: ".$this->container->errorString);
598 0 : $this->writeToLogFile("Container: ".$this->container->errorString, "");
599 : }
600 0 : }
601 0 : $this->writeToLogFile("FERTIG", "");
602 0 : $this->closeLogFile();
603 0 : }
604 0 : return true;
605 : }
606 : }
607 : /**
608 : * Ruft die Methoden auf, die automatisierte Funktionen ausführen, wenn eine Veranstaltung reaktiviert wird.
609 : *
610 : * @access public
611 : * @param integer $courseID - die ID der Veranstaltung
612 : * @return bool - Erfolgwert
613 : */
614 : function reactivateCourse($courseID) {
615 0 : if (!is_numeric($courseID)) {
616 0 : $this->error("Keine gültige courseID übergeben");
617 0 : return false;
618 : } else {
619 0 : $count = $this->container->count();
620 0 : if ($count > 0) {
621 0 : $this->openLogFile();
622 0 : $this->writeToLogFile("REAKTIVIERE KURS $courseID: ".date("d.m.Y H:i:s"), "");
623 0 : for ($i = 0 ; $i < $count ; $i++) {
624 0 : $object = $this->container->get($i);
625 0 : if ($object != null) {
626 0 : $this->writeToLogfile("BEARBEITE OBJEKT NR. ".($i+1) .": ".$object->getInfo(), "");
627 0 : $object->setVerbose($this->verbose);
628 0 : $object->setFilePointer($this->logFilePointer);
629 0 : if (!$object->reactivateCourse($courseID)) {
630 0 : $this->writeToLogFile($object->echoErrorString("\r\n"), "");
631 0 : }
632 0 : } else {
633 0 : $this->writeToLogFile("BEARBEITE OBJEKT NR. ".($i+1), "");
634 0 : $this->error("Container: ".$this->container->errorString);
635 0 : $this->writeToLogFile("Container: ".$this->container->errorString, "");
636 : }
637 0 : }
638 0 : $this->writeToLogFile("FERTIG", "");
639 0 : $this->closeLogFile();
640 0 : }
641 0 : return true;
642 : }
643 : }
644 :
645 : /**
646 : * Ruft die Methoden auf, die automatisierte Funktionen ausführen, wenn eine
647 : * Veranstaltung neu erstellt wird.
648 : *
649 : * @access public
650 : * @param integer $courseID - die ID der Veranstaltung
651 : * @return bool - Erfolgwert
652 : */
653 : function newCourse($courseID) {
654 0 : if (!is_integer($courseID)) {
655 0 : $this->error("Keine gültige courseID übergeben");
656 0 : return false;
657 : } else {
658 0 : $count = $this->container->count();
659 0 : if ($count > 0) {
660 0 : $this->openLogFile();
661 0 : $this->writeToLogFile("NEUER KURS $courseID: ".date("d.m.Y H:i:s"), "");
662 0 : for ($i = 0 ; $i < $count ; $i++) {
663 0 : $object = $this->container->get($i);
664 0 : if ($object != null) {
665 0 : $this->writeToLogfile("BEARBEITE OBJEKT NR. ".($i+1) .": ".$object->getInfo(), "");
666 0 : $object->setVerbose($this->verbose);
667 0 : $object->setFilePointer($this->logFilePointer);
668 0 : if (!$object->newCourse($courseID)) {
669 0 : $this->writeToLogFile($object->echoErrorString("\r\n"), "");
670 0 : }
671 0 : } else {
672 0 : $this->writeToLogFile("BEARBEITE OBJEKT NR. ".($i+1), "");
673 0 : $this->error("Container: ".$this->container->errorString);
674 0 : $this->writeToLogFile("Container: ".$this->container->errorString, "");
675 : }
676 0 : }
677 0 : $this->writeToLogFile("FERTIG", "");
678 0 : $this->closeLogFile();
679 0 : }
680 0 : return true;
681 : }
682 : }
683 :
684 :
685 : /**
686 : * Ruft die Methoden auf, die automatisierte Funktionen ausführen, wenn eine
687 : * eCommunity neu erstellt wird.
688 : *
689 : * @access public
690 : * @param integer $courseID - die ID der Veranstaltung
691 : * @return bool - Erfolgwert
692 : */
693 : public function newEcommunity($courseID) {
694 0 : if (!is_integer($courseID)) {
695 0 : $this->error("Keine gültige courseID übergeben");
696 :
697 0 : return false;
698 :
699 : } else {
700 0 : $count = $this->container->count();
701 :
702 0 : if ($count > 0) {
703 0 : $this->openLogFile();
704 0 : $this->writeToLogFile("NEUE ECOMMUNTIY $courseID: " . date("d.m.Y H:i:s"), "");
705 :
706 0 : for ($i = 0 ; $i < $count ; $i++) {
707 0 : $object = $this->container->get($i);
708 :
709 0 : if ($object != null) {
710 0 : $this->writeToLogfile("BEARBEITE OBJEKT NR. ".($i+1) .": ".$object->getInfo(), "");
711 0 : $object->setVerbose($this->verbose);
712 0 : $object->setFilePointer($this->logFilePointer);
713 :
714 0 : if (!$object->newCourse($courseID))
715 0 : $this->writeToLogFile($object->echoErrorString("\r\n"), "");
716 :
717 0 : if (!$object->newEcommunity($courseID))
718 0 : $this->writeToLogFile($object->echoErrorString("\r\n"), "");
719 :
720 0 : } else {
721 0 : $this->writeToLogFile("BEARBEITE OBJEKT NR. ".($i+1), "");
722 0 : $this->error("Container: ".$this->container->errorString);
723 0 : $this->writeToLogFile("Container: ".$this->container->errorString, "");
724 : }
725 0 : }
726 :
727 0 : $this->writeToLogFile("FERTIG", "");
728 0 : $this->closeLogFile();
729 0 : }
730 :
731 0 : return true;
732 : }
733 : }
734 :
735 :
736 :
737 : /**
738 : * Aufzurufen, wenn die Benutzergruppe eines User geändert wird.
739 : *
740 : * @access public
741 : * @param integer $userID - die ID des Users
742 : * @param integer $oldGroup - die alte Benutzergruppe
743 : * @return bool - Erfolgwert
744 : */
745 : function changeUserGroup($userID, $oldGroup) {
746 0 : if (is_numeric($userID) and is_numeric($oldGroup)) {
747 0 : $count = $this->container->count();
748 0 : if ($count > 0) {
749 0 : $this->openLogFile();
750 0 : $this->writeToLogFile("ÄNDERE BENUTZERGRUPPE FÜR ($userID) VON ($oldGroup) IN EINE NEUE: ".date("d.m.Y H:i:s"), "");
751 0 : for ($i = 0 ; $i < $count ; $i++) {
752 0 : $object = $this->container->get($i);
753 0 : if ($object != null) {
754 0 : $this->writeToLogfile("BEARBEITE OBJEKT NR. ".($i+1) .": ".$object->getInfo(), "");
755 0 : $object->setVerbose($this->verbose);
756 0 : $object->setFilePointer($this->logFilePointer);
757 0 : if (!$object->changeUserGroup($userID, $oldGroup)) {
758 0 : $this->writeToLogFile($object->echoErrorString("\r\n"), "");
759 0 : }
760 0 : } else {
761 0 : $this->writeToLogFile("BEARBEITE OBJEKT NR. ".($i+1), "");
762 0 : $this->error("Container: ".$this->container->errorString);
763 0 : $this->writeToLogFile("Container: ".$this->container->errorString, "");
764 : }
765 0 : }
766 0 : $this->writeToLogFile("FERTIG", "");
767 0 : $this->closeLogFile();
768 0 : }
769 0 : } else {
770 0 : $this->error("Keine gültige userID oder oldGroup übergeben!");
771 0 : return false;
772 : }
773 0 : return true;
774 : }
775 : /**
776 : * Aufzurufen, wenn die Benutzergruppe eines User in einem Kurs geändert wird.
777 : *
778 : * @access public
779 : * @param integer $userID - die ID des Users
780 : * @param integer $courseID - die ID des Kurses
781 : * @param integer $oldGroup - die alte Benutzergruppe
782 : * @param integer $newGroup - die neue Benutzergruppe
783 : * @return bool - Erfolgwert
784 : */
785 : function changeUserGroupInCourse($userID, $courseID, $oldGroup, $newGroup) {
786 0 : if (is_numeric($userID) && is_numeric($oldGroup) && is_numeric($courseID) && is_numeric($newGroup)) {
787 0 : $count = $this->container->count();
788 0 : if ($count > 0) {
789 0 : $this->openLogFile();
790 0 : $this->writeToLogFile("ÄNDERE BENUTZERGRUPPE FÜR ($userID) IM KURS ($courseID) VON ($oldGroup) IN ($newGroup): ".date("d.m.Y H:i:s"), "");
791 0 : for ($i = 0 ; $i < $count ; $i++) {
792 0 : $object = $this->container->get($i);
793 0 : if ($object != null) {
794 0 : $this->writeToLogfile("BEARBEITE OBJEKT NR. ".($i+1) .": ".$object->getInfo(), "");
795 0 : $object->setVerbose($this->verbose);
796 0 : $object->setFilePointer($this->logFilePointer);
797 0 : if (!$object->changeUserGroupInCourse($userID, $courseID, $oldGroup, $newGroup)) {
798 0 : $this->writeToLogFile($object->echoErrorString("\r\n"), "");
799 0 : }
800 0 : } else {
801 0 : $this->writeToLogFile("BEARBEITE OBJEKT NR. ".($i+1), "");
802 0 : $this->error("Container: ".$this->container->errorString);
803 0 : $this->writeToLogFile("Container: ".$this->container->errorString, "");
804 : }
805 0 : }
806 0 : $this->writeToLogFile("FERTIG", "");
807 0 : $this->closeLogFile();
808 0 : }
809 0 : } else {
810 0 : $this->error("Keine gültige userID oder oldGroup übergeben!");
811 0 : return false;
812 : }
813 0 : return true;
814 : }
815 : /**
816 : * Aufzurufen, wenn sich die User-Daten eines Benutzers geändert haben.
817 : * Diese Daten betreffen die Einträge in den Tabellen <strong>user</strong> und <strong>user_hompage</strong>.
818 : * Zu beachten ist, das diese Methode nur dann aufgerufen werden soll, wenn das Ergeigniss
819 : * das ihre Ausführung erfordert nicht von einer der anderen Methoden abgedeckt wird.<br />
820 : * Also sollte im Falle eines neuen Assistenten in einem Kurs die Methode
821 : * {@link Automation::addAssistentToCourse() addAssistentToCourse()} aufgerufen werden und
822 : * nicht diese Methode. Das Gleiche gilt für {@link Automation:: changeUserGroup() changeUserGroup()},
823 : * und alle anderen Methoden die einen Spezialfall abdecken!
824 : *
825 : * @access public
826 : * @param integer $userID - die ID des Benutzers
827 : * @return bool - Erfolgwert
828 : */
829 : function updateUser($userID) {
830 0 : if (is_numeric($userID)) {
831 0 : $count = $this->container->count();
832 0 : if ($count > 0) {
833 0 : $this->openLogFile();
834 0 : $this->writeToLogFile("AKTUALISIERE BENUTZERDATEN VON ($userID): ".date("d.m.Y H:i:s"), "");
835 0 : for ($i = 0 ; $i < $count ; $i++) {
836 0 : $object = $this->container->get($i);
837 0 : if ($object != null) {
838 0 : $this->writeToLogfile("BEARBEITE OBJEKT NR. ".($i+1) .": ".$object->getInfo(), "");
839 0 : $object->setVerbose($this->verbose);
840 0 : $object->setFilePointer($this->logFilePointer);
841 0 : if (!$object->updateUser($userID)) {
842 0 : $this->writeToLogFile($object->echoErrorString("\r\n"), "");
843 0 : }
844 0 : } else {
845 0 : $this->writeToLogFile("BEARBEITE OBJEKT NR. ".($i+1), "");
846 0 : $this->error("Container: ".$this->container->errorString);
847 0 : $this->writeToLogFile("Container: ".$this->container->errorString, "");
848 : }
849 0 : }
850 0 : $this->writeToLogFile("FERTIG", "");
851 0 : $this->closeLogFile();
852 0 : }
853 0 : } else {
854 0 : $this->error("Keine gültige userID übergeben!");
855 0 : return false;
856 : }
857 0 : return true;
858 : }
859 : /**
860 : * Aufzurufen, wenn sich ein neuer User am Portal anmeldet.
861 : *
862 : * @access public
863 : * @param integer $userID - die ID des Users
864 : * @return bool - Erfolgwert
865 : */
866 : function newUser($userID) {
867 0 : if (!is_numeric($userID)) {
868 0 : $this->error("Keine gültige userID übergeben!");
869 0 : return false;
870 : } else {
871 0 : $count = $this->container->count();
872 0 : if ($count > 0) {
873 0 : $this->openLogFile();
874 0 : $this->writeToLogFile("NEUER USER $userID: ".date("d.m.Y H:i:s"), "");
875 0 : for ($i = 0 ; $i < $count ; $i++) {
876 0 : $object = $this->container->get($i);
877 0 : if ($object != null) {
878 0 : $this->writeToLogfile("BEARBEITE OBJEKT NR. ".($i+1) .": ".$object->getInfo(), "");
879 0 : $object->setVerbose($this->verbose);
880 0 : $object->setFilePointer($this->logFilePointer);
881 0 : if (!$object->newUser($userID)) {
882 0 : $this->writeToLogFile($object->echoErrorString("\r\n"), "");
883 0 : }
884 0 : } else {
885 0 : $this->writeToLogFile("BEARBEITE OBJEKT NR. ".($i+1), "");
886 0 : $this->error("Container: ".$this->container->errorString);
887 0 : $this->writeToLogFile("Container: ".$this->container->errorString, "");
888 : }
889 0 : }
890 0 : $this->writeToLogFile("FERTIG", "");
891 0 : $this->closeLogFile();
892 0 : }
893 0 : return true;
894 : }
895 : }
896 : /**
897 : * Fügt am Errorstring eine Fehlermeldung an.
898 : * @access protected
899 : * @param string $mesage - Die Fehlermeldung
900 : * @return void
901 : */
902 : function error($message) {
903 0 : if (is_string($message)) {
904 0 : $this->errorString[] = $message;
905 0 : }
906 0 : }
907 : /**
908 : * Fügt die Fehlermeldungen zu einem String zusammen und gibt diesen zurück.
909 : * Beim Separator handelt es sich um eine Zeichenkette die zwischen die einzelnen
910 : * Fehlermeldungen eingefügt werden. So ist es möglich, z.B. Zeilenumbrüche oder
911 : * ähnliches einzufügen.
912 : * @access public
913 : * @param string $separator - Der Separator
914 : * @return string - den zusammengesetzten Errorstring
915 : */
916 : function echoErrorString($separator = ' ') {
917 0 : if (!is_string($separator)) {
918 0 : $separator = " ";
919 0 : }
920 0 : return implode($separator, $this->errorString);
921 : }
922 : /**
923 : * Öffnet das Logfile im APPEND-Modus.
924 : * Falls kein Logfile angegeben wurde, oder ein Fehler auftrat, gibt
925 : * die Methode false zurück und das Logfile wird nicht geöffnet.
926 : * @access protected
927 : * @return bool - Erfolgswert
928 : */
929 : function openLogFile() {
930 0 : $handle = fopen($this->logFile, "a");
931 0 : if ($handle === false) {
932 0 : $this->logFilePointer = 0;
933 0 : return false;
934 : } else {
935 0 : $this->logFilePointer = $handle;
936 0 : return true;
937 : }
938 : }
939 : /**
940 : * Schließt das Logfile
941 : * @access protected
942 : * @return void
943 : */
944 : function closeLogFile() {
945 : // Noch einen Zeilenumbruch zum besseren Trennen verschiedener Aktionen
946 0 : fwrite($this->logFilePointer, "\n");
947 0 : fclose($this->logFilePointer);
948 0 : }
949 : /**
950 : * Schreibt eine Nachricht in das Logfile.
951 : * Die Nachricht wird automatisch mit einem <strong>\n</strong> versehen <br />
952 : * (bei Windows-Systemen mit einem <strong>\r\n</strong>).<br />
953 : * Falls {@link $verbose <strong>verbose</strong>} <em>true</em> ist, wird die Nachricht auch an den Browser gesendet.<br />
954 : * Falls ein Fehler beim öffnen des Logfiles auftrat, oder es noch nicht geöffnet
955 : * wurde, wird das Schreiben ins Logfile ignoriert. Evtl. Ausgaben an den Browser werden
956 : * aber trotzdem gemacht.
957 : * @access protected
958 : * @param string $message - die Nachricht
959 : * @param string $indent - Einrückung (Standardmäßig 4 Leerzeichen)
960 : * @return void
961 : */
962 : function writeToLogfile($message, $indent = " ") {
963 0 : if ($this->verbose) {
964 0 : echo "$message<br />\n";
965 0 : }
966 0 : if ($this->logFilePointer != 0) {
967 0 : fwrite($this->logFilePointer, "$indent$message\n");
968 0 : }
969 0 : }
970 : }
|